<?php

namespace app\admin\model;

use app\admin\model\AuthGroup;
use fast\Tree;
use think\Cache;
use think\Db;
use think\Exception;
use think\Model;

class DepartmentAdmin extends Model
{
    // 表名
    protected $name = 'department_admin';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected static $instance;
    /**
     * 初始化
     * @access public
     * @param array $options 参数
     * @return Tree
     */
    public static function instance($options = [])
    {
        if (is_null(self::$instance)) {
            self::$instance = new static($options);
        }

        return self::$instance;
    }

    /**
     * 关联部门中间表
     * @return \think\model\relation\HasMany
     */
    public function department()
    {
      //  return $this->hasOne('\app\admin\model\Department', 'id', 'department_id');
        return $this->belongsTo('\app\admin\model\Department', 'department_id', 'id');

    }


    /**
     * 获取员工者的部门ids
     * @param $admin_id
     * @param bool $is_principal 是否取负责部门
     * @return array|bool|string
     */
    public static function getDepartmentIds($admin_id)
    {
        $model = new self();
        return $model->where('admin_id', $admin_id)->column('department_id');
    }




}